import { request } from "@/utils/http";
import type { GetInfoResponse, LoginResponse } from "./model/userTypes";

// 登录
export const reqLogin = (username: string, password: string) => {
  // <any, string>的第一个类型为any即可，实际不会用上
  // 第二个类型是返回值数据中data的类型，根据接口文档填写
  return request.post<any, LoginResponse>("/admin/acl/index/login", {
    username,
    password,
  });
};

// 登出
export const reqLogout = () => {
  return request.post<any, null>("/admin/acl/index/logout");
};

// 查询用户信息
export const reqGetInfo = () => {
  return request.get<any, GetInfoResponse>("/admin/acl/index/info");
};

export const reqGetTradeMark = (page: any, limit: any) => request.get<any, any>(`admin/product/baseTrademark/${page}/${limit}`)
// 新增品牌或修改品牌
export const reqAddOrUpdateTradeMark = (data: any) => {
  if (data.id) {
    return request.put('/admin/product/baseTrademark/update', data)
  } else {
    return request.post('/admin/product/baseTrademark/save', data)
  }
}
// 删除品牌
export const reqDeleteTradeMark = (id: any) => request.delete(`/admin/product/baseTrademark/remove/${id}`)

/* 
后台用户管理相关的API请求函数
*/

const api_name = '/admin/acl/user'
// 用户管理列表请求
export const reqGetPageList = (page:any, limit:any, searchObj:any) => {

  return request.get<any, any>(`${api_name}/${page}/${limit}`, {
    params: {
      username: searchObj,
    },
  })
}
// 根据ID获取某个后台用户
export const reqGetById = (id:any) => {
  return request.get<any, any>(`${api_name}/get/${id}`)
}

//   保存一个新的后台用户
export const reqAdd = (data:any) => {
  return request.post<any, any>(`${api_name}/save`, data)
}
//  更新一个后台用户
export const reqUpdate = (data:any) => {
  return request.put<any, any>(`${api_name}/update`, data)
}
//   获取某个用户的所有角色
export const reqGetRoles = (userId:any) => {
  return request.get<any, any>(`${api_name}/toAssign/${userId}`)
}

// 给某个用户分配角色
export const reqAssignRoles = (userId:any, roleId:any) => {

  return request.post(`${api_name}/doAssign?userId=${userId}&roleId=${roleId}`
  )
}

// 删除某个用户

export const reqRemoveById = (id:any) => {
  return request.delete(`${api_name}/remove/${id}`)
}

//批量删除多个用户
//ids的结构: ids是包含n个id的数组

export const reqRemoveUsers = (ids:any) => {
  return request(`${api_name}/batchRemove`, { data: ids })
}